package com.example.word.controller;

import com.example.word.dto.WordBackInfoDTO;
import com.example.word.enums.FilePathEnum;
import com.example.word.service.WordInfoService;
import com.example.word.strategy.context.UploadStrategyContext;
import com.example.word.vo.Result;
import com.example.word.vo.WebsiteConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 文档检测信息控制器
 * @author yuwen
 * @date 2023/4/1
 */
@Api(tags = "文档检测信息模块")
@RestController
public class WordInfoController {
    @Autowired
    private WordInfoService wordInfoService;
    @Autowired
    private UploadStrategyContext uploadStrategyContext;
    /**
     * 上传访客信息
     *
     * @return {@link Result}
     */
    @PostMapping("/report")
    public Result<?> report() {
        wordInfoService.report();
        return Result.ok();
    }

    /**
     * 查看后台信息
     *
     * @return {@link Result<WordBackInfoDTO>} 后台信息
     */
    @ApiOperation(value = "查看后台信息")
    @GetMapping("/admin")
    public Result<WordBackInfoDTO> getWordBackInfo() {
        return Result.ok(wordInfoService.getWordBackInfo());
    }
    /**
     * 上传文档检测系统配置图片
     *
     * @param file 文件
     * @return {@link Result<String>} 文档检测系统配置图片
     */
    @ApiOperation(value = "上传文档检测系统配置图片")
    @ApiImplicitParam(name = "file", value = "图片", required = true, dataType = "MultipartFile")
    @PostMapping("/admin/config/images")
    public Result<String> savePhotoAlbumCover(MultipartFile file) {
        return Result.ok(uploadStrategyContext.executeUploadStrategy(file, FilePathEnum.CONFIG.getPath()));
    }
    /**
     * 更新网站配置
     *
     * @param websiteConfigVO 网站配置信息
     * @return {@link Result}
     */
    @ApiOperation(value = "更新网站配置")
    @PutMapping("/admin/website/config")
    public Result<?> updateWebsiteConfig(@Valid @RequestBody WebsiteConfigVO websiteConfigVO) {
        wordInfoService.updateWebsiteConfig(websiteConfigVO);
        return Result.ok();
    }
    /**
     * 获取网站配置
     *
     * @return {@link Result<WebsiteConfigVO>} 网站配置
     */
    @ApiOperation(value = "获取网站配置")
    @GetMapping("/admin/website/config")
    public Result<WebsiteConfigVO> getWebsiteConfig() {
        return Result.ok(wordInfoService.getWebsiteConfig());
    }




}
